package work.mediway.mdm.core.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;
import work.mediway.mdm.core.exception.DataException;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/9/1
 */
public enum ServiceTypeEnum {

    /**
     * REG
     */
    REG(""),

    /**
     * PUB
     */
    PUB(""),

    /**
     * SOAP
     */
    SOAP("SoapServiceCallStrategyImpl"),

    /**
     * REST
     */
    REST("RestServiceCallStrategyImpl");

    /**
     * 策略实现类对应的 beanName
     */
    @Setter
    @Getter
    private String beanName;

    ServiceTypeEnum(String beanName) {
        this.beanName = beanName;
    }

    public static ServiceTypeEnum getEnum(String type) {
        for (ServiceTypeEnum typeEnum : ServiceTypeEnum.values()) {
            if (StrUtil.equalsIgnoreCase(typeEnum.name(), type)) {
                return typeEnum;
            }
        }
        throw new DataException(StrUtil.format("[ type = {} ] 不存在", type));
    }
}
